
package cn.csust.net2.manager.server.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.csust.net2.manager.server.dao.CellDAO;
import cn.csust.net2.manager.server.dao.PairCellDAO;
import cn.csust.net2.manager.server.dao.TableDAO;
import cn.csust.net2.manager.server.dao.TableResultDAO;
import cn.csust.net2.manager.server.util.TableFactory;
import cn.csust.net2.manager.shared.exception.BeyondAuthorityException;
import cn.csust.net2.manager.shared.po.PairCell;
import cn.csust.net2.manager.shared.po.Table;
import cn.csust.net2.manager.shared.po.Teacher;
import cn.csust.net2.manager.shared.service.ExamineInfoService;
import cn.csust.net2.manager.shared.util.Constant;
import cn.csust.net2.manager.shared.util.ServiceConstant;
import cn.csust.net2.manager.shared.vo.TableVO;
@Service(value = ServiceConstant.SERVICE_NAME_EXAMINEINFOSERVICE)
public class ExamineInfoServiceImpl extends BaseServiceImpl implements ExamineInfoService{
	@Resource(name = Constant.DAO_NAME_CELL)
	private CellDAO cellDAO;
	@Resource(name = Constant.DAO_NAME_PAIRCELL)
	private PairCellDAO pairCellDAO;
	@Resource(name = Constant.DAO_NAME_TABLE)
	private TableDAO tableDAO;
	@Resource(name = Constant.DAO_NAME_TABLE_RESULT)
	private TableResultDAO tableResultDAO;
	@Override
	@Transactional
	public TableVO enterExamine(String name)throws BeyondAuthorityException {
		TableVO tableVO = TableFactory.buildTable("D:\\1.doc");
		Table table = tableVO.getTable();
		Teacher t = tableDAO.findUniqueHQL_T(" from Teacher where teacherNumber = 111");
		table.setUser(t);
		
		tableDAO.save(table);
		List<PairCell> list = tableVO.getList();
		for(PairCell pairCell:list){
			pairCell.setTable(table);
			pairCellDAO.save(pairCell);
			System.out.println("保存成功");
		}
		List<PairCell> list1 = tableDAO.findListByHQL_T(" from PairCell c where c.table.wordTableID = "+table.getWordTableID());
		TableVO tt = new TableVO();
		tt.setTable(table);
		tt.setList(list1);
		return tt;
	}
	@Override
	@Transactional
	public TableVO loadExamine(Table table) throws BeyondAuthorityException{
		List<PairCell> list1 = tableDAO.findListByHQL_T(" from PairCell c where c.table.wordTableID = "+table.getWordTableID());
		TableVO tt = new TableVO();
		tt.setTable(table);
		tt.setList(list1);
		return tt;
	}
	public CellDAO getCellDAO() {
		return cellDAO;
	}
	public void setCellDAO(CellDAO cellDAO) {
		this.cellDAO = cellDAO;
	}
	public PairCellDAO getPairCellDAO() {
		return pairCellDAO;
	}
	public void setPairCellDAO(PairCellDAO pairCellDAO) {
		this.pairCellDAO = pairCellDAO;
	}
	public TableDAO getTableDAO() {
		return tableDAO;
	}
	public void setTableDAO(TableDAO tableDAO) {
		this.tableDAO = tableDAO;
	}
	public TableResultDAO getTableResultDAO() {
		return tableResultDAO;
	}
	public void setTableResultDAO(TableResultDAO tableResultDAO) {
		this.tableResultDAO = tableResultDAO;
	}
}

